<template>
  <div class="main">
    <div class="mainBox">
      <div class="leftBox">
        <img class="img" src="../../assets/image/login.png" alt="" srcset="" />
        <div class="title">专注保护爱车的每一个细节！</div>
      </div>
      <div class="regthBox">
        <div class="regthBoxTitle">酷德官网后台</div>
        <el-form :model="formAdd" ref="formAdd" label-width="auto" style="max-width: 600px">
          <el-form-item label="登录账号：">
            <el-input v-model="form.account" />
          </el-form-item>
          <el-form-item label="登录密码：">
            <el-input v-model="form.password" show-password />
          </el-form-item>
        </el-form>
        <div class="footButton center">
          <div class="button center" @click="registerFn">登录</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { login } from '@/http/api/login'
import { ElMessage } from 'element-plus'
import Cookie from 'js-cookie'
import { useRouter } from "vue-router"
import { ref, reactive, onMounted } from 'vue'
const router = useRouter()
let form = reactive({})
const registerFn = async () => {
  if (form.account && form.password) {
    try {
      const res = await login(form)
      ElMessage.success(res.data.res.message)
      Cookie.set('token', res.data.token)
      router.push('/Layout')
      localStorage.setItem('userInfo', JSON.stringify(res.data.res))
    } catch (error) {
      ElMessage.error(error.response.data.message)
    }

  } else {
    ElMessage.error('请补充完整信息')
  }

}

</script>

<style lang="scss" scoped>
.main {
  height: 100vh;
  width: 100vw;
  display: flex;
  justify-content: center;
}
.mainBox {
  display: flex;
  align-content: center;
  flex-wrap: wrap-reverse;
}
.leftBox {
  .img {
    width: 720px;
    height: 221.95px;
  }
  .title {
    font-size: 58px;
    color: rgba(64, 149, 229, 1);
    font-weight: bold;
  }
}
.regthBox {
  width: 400px;
  height: 300px;
  .regthBoxTitle {
    font-size: 46px;
    color: rgba(64, 149, 229, 1);
    font-weight: bold;
    display: flex;
    justify-content: center;
    margin-bottom: 75px;
  }
}
.footButton {
  display: flex;
  align-items: center;
  justify-content: center;
  .button {
    width: 200px;
    height: 55px;
    border-radius: 20px;
    background-color: rgba(62, 130, 244, 1);
    color: rgba(255, 255, 255, 1);
    font-size: 20px;
    flex-wrap: wrap;
    cursor: pointer;
    user-select: none;
  }
  .button:active {
    background-color: rgba(62, 130, 244, 0.8);
  }
}
</style>